package cn.sccdlg.spring5.ui;

import cn.sccdlg.spring5.service.AccountService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author RaoShuang
 * @emil 991207823@qq.com
 * @date 2020/10/18 10:11
 * 模拟一个表现层，用于调用业务层
 */
public class Client {

    /**
     * @param args
     */
    public static void main(String[] args) {
        //1.获取核心容器对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        //2.根据id获取Bean对象
        //2-1 构造函数注入
        AccountService as  = (AccountService)ac.getBean("accountService");
        as.saveAccount();
        System.out.println("******分割线******");

        //2-2-1 set方法注入
        AccountService as2  = (AccountService)ac.getBean("accountService2");
        as2.saveAccount();
        //2-2-2 使用 p 名称空间注入数据
        AccountService as3  = (AccountService)ac.getBean("accountService3");
        as3.saveAccount();
        System.out.println("******分割线******");

        //2-2-1 复杂类型的注入/集合类型的注入
        AccountService as4  = (AccountService)ac.getBean("accountService4");
        as4.saveAccount();
    }

}
